﻿using UnityEditor;
using System.Collections;
using UnityEngine;
using System.IO;
using System.Collections.Generic;

namespace QFramework.Editor
{
    public class QABEditor
    {

        public static string ABCONFIGPATH = @"Assets\EzFreamWork\Editor\ABConfig.asset";
        [MenuItem("EzFreamWork/AssetBundle/BuildWin64")]
        public static void BuildAssetBundle()
        {
            ABConfig aBConfig = AssetDatabase.LoadAssetAtPath<ABConfig>(ABCONFIGPATH);
          
            foreach (var item in aBConfig.m_AllPrefabPath)
            {
                Debug.Log(item);
            }
            // string outPath = Application.streamingAssetsPath + "/AssetBundle";
            // // AB包输出路径
            // // 检查路径是否存在
            // CheckDirAndCreate(outPath);
            // BuildPipeline.BuildAssetBundles(outPath, 0, BuildTarget.StandaloneWindows64);
            // // 刚创建的文件夹和目录能马上再Project视窗中出现
            // AssetDatabase.Refresh();
        }
        [MenuItem("EzFreamWork/AssetBundle/BuildIos")]
        public static void BuildAssetBundle1()
        {
            // AB包输出路径
            string outPath = Application.streamingAssetsPath + "/AssetBundle";

            // 检查路径是否存在
            CheckDirAndCreate(outPath);

            BuildPipeline.BuildAssetBundles(outPath, 0, BuildTarget.iOS);

            // 刚创建的文件夹和目录能马上再Project视窗中出现
            AssetDatabase.Refresh();
        }
        [MenuItem("EzFreamWork/AssetBundle/BuildAndroid")]
        public static void BuildAssetBundle2()
        {
            // AB包输出路径
            string outPath = Application.streamingAssetsPath + "/AssetBundle";
            // 检查路径是否存在
            CheckDirAndCreate(outPath);
            AssetBundleManifest assetBundleManifest = BuildPipeline.BuildAssetBundles(outPath, 0, BuildTarget.Android);
            // 刚创建的文件夹和目录能马上再Project视窗中出现
            AssetDatabase.Refresh();
        }

        /// <summary>
        /// 判断路径是否存在,不存在则创建
        /// </summary>
        public static void CheckDirAndCreate(string dirPath)
        {
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }
        }
    }
}
